package com.kebabeaters.nakebab.client.presenter;

import com.google.gwt.event.dom.client.HasAllMouseHandlers;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.ContentSlot;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.proxy.Proxy;
import com.gwtplatform.mvp.client.proxy.RevealContentHandler;
import com.gwtplatform.mvp.client.proxy.RevealRootContentEvent;
import com.kebabeaters.nakebab.client.event.NavigationAutoModeRequest;
import com.kebabeaters.nakebab.client.presenter.widget.CircleLayoutPresenterWidget;

public class ContentPresenter extends
		Presenter<ContentPresenter.Display, ContentPresenter.IProxy> {

	@ContentSlot
	public static final Type<RevealContentHandler<?>> TYPE_Navigation = new Type<RevealContentHandler<?>>();

	@ContentSlot
	public static final Type<RevealContentHandler<?>> TYPE_Content = new Type<RevealContentHandler<?>>();

	public interface Display extends View {

		HasAllMouseHandlers getAllMouseHandlers();
	}

	@ProxyCodeSplit
	public interface IProxy extends Proxy<ContentPresenter> {
	}

	@Inject
	public ContentPresenter(EventBus eventBus, Display view, IProxy proxy,
			CircleLayoutPresenterWidget circleLayout) {
		super(eventBus, view, proxy);

		setInSlot(TYPE_Navigation, circleLayout);
	}

	@Override
	protected void onBind() {
		super.onBind();

		getView().getAllMouseHandlers().addMouseOverHandler(
				new MouseOverHandler() {

					@Override
					public void onMouseOver(MouseOverEvent event) {
						getEventBus()
								.fireEvent(new NavigationAutoModeRequest());
					}
				});
	}

	@Override
	protected void revealInParent() {
		RevealRootContentEvent.fire(this, this);
	}
}
